<?php 
namespace app\api\controller;
use think\Controller;
use think\facade\Session;
use auth\Auth;
/**
 * 
 */
class Base extends Controller{
	
	public function __construct() {
        parent::__construct();
     //    $this->userInfo = [];
    	$this->user = Session::get('user');
        $this->getAdmin();
    }

    function getAdmin(){
        if(in_array(request()->action(),array('login','logout','verify')) || in_array(request()->controller(),array('Ueditor','Uploadify'))){
            //return;
        }else{
            if(!$this->user){
            	$data['status'] = 0;
            	$data['data'] = null;
            	$data['msg'] = "用户信息已经过期，请重新登录";
                exit(returnJson(201,$data));
            }else{
                // $this->adminInfo = db('administrator')->where('id = '.$this->admin_id)->find();
                // $this->check();
            }
        }
    }

    function check(){
        if ($this->admin_id == 1) {
            return true;
        }
        $name = request()->module() . '/' . request()->controller() . '/' . request()->action();
        $auth = new Auth();
        $res = $auth->check($name,$this->admin_id);
        if(!$res){
        	$data['code'] = 40000;
        	$data['data'] = null;
        	$data['msg'] = "您没有操作权限,请联系超级管理员分配权限";
            exit(json_encode($data));
        }
    }
}